﻿<cfsilent>

	<cfset event.setArg("pageTitle", "教学运行基础数据 - 培养方案修订 - 培养方案数据概况") />

	<cfset sql = "SELECT sbj_name, sbj_id, schooling_length 
					FROM t_subject 
					WHERE sbj_id = :sbjId " />
                    
    <cfset queryObj = new query( datasource=application.dnsSlave ) />
    <cfset queryObj.addParam( name="sbjId", value=event.getArg("SubID"), cfsqltype="cf_sql_varchar" ) />
    
    <cfset rs_subject = queryObj.execute( sql=sql ).getResult() /> 
    
	<cfset sql = "SELECT 
						credit, credit_required, credit_optional, 
						credit_relish, grade, period, period_required, 
						period_optional 
					FROM 
						t_condition 
					WHERE 
						con_id = :conId " />
                        
    <cfset queryObj = new query( datasource=application.dnsSlave ) />
    <cfset queryObj.addParam( name="conId", value=event.getArg("Schema"), cfsqltype="cf_sql_varchar" ) />
    
    <cfset rs_condition = queryObj.execute( sql=sql ).getResult() /> 
    
	<cfset sql = "SELECT 
						a.term_index, COUNT(*) count, 
						SUM( CASE a.prop_id WHEN '1' THEN t_course.course_credit ELSE 0 END ) sum3, 
						SUM( CASE a.prop_id WHEN '2' THEN t_course.course_credit ELSE 0 END ) sum4,
						SUM( CASE a.prop_id WHEN '1' THEN 1 ELSE 0 END ) sum5,
						SUM( CASE a.prop_id WHEN '2' THEN 1 ELSE 0 END ) sum6  
					FROM 
						t_schema a 
						INNER JOIN t_course ON t_course.cid = a.cid 
					WHERE 
						a.grade = :grade 
						AND 
						( a.sbj_id = :subjectId 
						  OR 
						  a.sbj_id LIKE :subjectDirs   
						) 
					GROUP BY 
						a.term_index 
					ORDER BY 
						a.term_index " />
                        
    <cfset queryObj = new query( datasource=application.dnsSlave ) />
    <cfset queryObj.addParam( name="grade", value=event.getArg("Edition"), cfsqltype="cf_sql_char" ) />
    <cfset queryObj.addParam( name="subjectId", value=event.getArg("SubID"), cfsqltype="cf_sql_varchar" ) />
    <cfset queryObj.addParam( name="subjectDirs", value=event.getArg("SubID")&"_", cfsqltype="cf_sql_varchar" ) />
    
    <cfset rs_schemaSummary = queryObj.execute( sql=sql ).getResult() /> 
  	
	<cfset sql = "SELECT grade 
					FROM t_schema 
					WHERE 
						( sbj_id = :subjectId OR sbj_id LIKE :subjectDirs )  
						AND
						( grade > :currentGrade OR grade < :currentGrade ) 
					GROUP BY grade 
					ORDER BY grade DESC " />
                    
    <cfset queryObj = new query( datasource=application.dnsSlave ) />
    <cfset queryObj.addParam( name="currentGrade", value=event.getArg("Edition"), cfsqltype="cf_sql_char" ) />
    <cfset queryObj.addParam( name="subjectId", value=event.getArg("SubID"), cfsqltype="cf_sql_varchar" ) />
    <cfset queryObj.addParam( name="subjectDirs", value=event.getArg("SubID")&"_", cfsqltype="cf_sql_varchar" ) />
    
    <cfset rs_fromEditions = queryObj.execute( sql=sql ).getResult() /> 
    
	<cfset mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice") />

	<cfset targetArgs = structNew() />
	<cfset structInsert(targetArgs, "SubID", event.getArg("SubID"), true) />
	<cfset structInsert(targetArgs, "Edition", event.getArg("Edition"), true) />
	<cfset structInsert(targetArgs, "Schema", event.getArg("Schema"), true) />

	<cfset passArgs = structNew() />

	<cfset currentTab = event.getArg("TabID", "labSummary") />
	
	<cfif rs_schemaSummary.recordCount eq 0>
		<cfset currentTab = event.getArg("TabID", "labCopy") />
	</cfif>

</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('programSchema')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">培养方案</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 edit"></i>培养方案修订 - <cfoutput>#rs_subject.sbj_name#</cfoutput>专业(<cfoutput>#event.getArg("Edition")#</cfoutput>)版
				</h2>
			</div>
		</div>
	</div>
</div>

<!--- 加载导航菜单 --->
<!-- stepMenu-->
<cfoutput>#event.getArg("stepMenu")#</cfoutput>
<!--/stepMenu-->

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab2">
					<div class="tabLables">
						<span <cfif currentTab eq "labSummary">class="active"</cfif> id="labSummary" tabTarget="Summary">概况</span>
						<cfif rs_fromEditions.recordCount>
							<span <cfif currentTab eq "labCopy">class="active"</cfif> id="labCopy" tabTarget="Copy">复制培养方案</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
					
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<div id="Summary" class="tabContent">
					
					<div class="noticeBlock">
						<h3>学期课程分布</h3>
						<p><span class="img icon16x16 message"></span>如果您需要从上一个年级复制课程设置信息, 请通过上方的 "复制培养方案" 标签进行操作.</p>
					</div>
					
					<cfif rs_schemaSummary.recordCount>
						<table class="UItable">
							<tr align="center">
								<td class="cellBorderPadding" colspan="2">学期</td>
                                <cfloop query="rs_schemaSummary">
									<cfset structInsert(targetArgs, "Term", rs_schemaSummary.term_index, true) />
									<td class="cellBorderPadding"><a href="<cfoutput>#buildURL('programSchemaWizardCourseByTerm', targetArgs)#</cfoutput>"><cfoutput>#mathAdvice.convertTermIdxToChinese(rs_schemaSummary.term_index)#</cfoutput></a></td>
								</cfloop>
								<cfset structDelete(targetArgs, "Term") />
							</tr>
							<tr align="center">
								<td width="12" class="cellBorderPadding" rowspan="2">学分</td>
								<td class="cellBorder">必修</td>
                                <cfloop query="rs_schemaSummary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#numberFormat(rs_schemaSummary.sum3, '0.0')#</cfoutput></span></td>
								</cfloop>
							</tr>
							<tr align="center">
								<td class="cellBorder">选修</td>
                                <cfloop query="rs_schemaSummary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#numberFormat(rs_schemaSummary.sum4, '0.0')#</cfoutput></span></td>
								</cfloop>
							</tr>
							<tr align="center">
								<td width="12" class="cellBorderPadding" rowspan="2">课程</td>
								<td class="cellBorder">必修</td>
                                <cfloop query="rs_schemaSummary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#rs_schemaSummary.sum5#</cfoutput></span></td>
								</cfloop>
							</tr>
							<tr align="center">
								<td class="cellBorder">选修</td>
                                <cfloop query="rs_schemaSummary">
									<td class="cellBorderPadding"><span class="number"><cfoutput>#rs_schemaSummary.sum6#</cfoutput></span></td>
								</cfloop>
							</tr>
						</table>
					</cfif>
					
					<div class="noticeBlock">
						<h3>学分要求</h3>
						<p><span class="img icon16x16 message"></span>如需对毕业生各项学分进行审核, 可以<a href="<cfoutput>#buildURL('programSchemaWizardCondition', targetArgs)#</cfoutput>">修订毕业学分学时要求</a></p>
						<cfif (rs_condition.credit + rs_condition.credit_required + rs_condition.credit_optional +rs_condition.credit_relish) gt 0>
						<p>毕业时必须达到如下条件</p>
						<ol>
							<cfif rs_condition.credit gt 0><li>总学分 <strong><cfoutput>#numberFormat(rs_condition.credit, "_._")#</cfoutput></strong></li></cfif>
							<cfif rs_condition.credit_required gt 0><li>必修课 <strong><cfoutput>#numberFormat(rs_condition.credit_required, "_._")#</cfoutput></strong></li></cfif>
							<cfif rs_condition.credit_optional gt 0><li>选修课 <strong><cfoutput>#numberFormat(rs_condition.credit_optional, "_._")#</cfoutput></strong></li></cfif>
							<cfif rs_condition.credit_relish gt 0><li>素质类通选课学分 <strong><cfoutput>#numberFormat(rs_condition.credit_relish, "_._")#</cfoutput></strong></li></cfif>
						</ol>
						<cfelse>
						<p><cfoutput>#rs_condition.grade#</cfoutput>级暂未设置毕业学分要求</p>
						</cfif>
					</div>
					
					<cfif (rs_condition.period + rs_condition.period_required + rs_condition.period_optional) gt 0>
					<div class="noticeBlock">
						<h3>修读学时要求</h3>
						<ol>
							<cfif rs_condition.period gt 0><li>总学时 <strong><cfoutput>#rs_condition.period #</cfoutput></strong></li></cfif>
							<cfif rs_condition.period_required gt 0><li>必修课 <strong><cfoutput>#rs_condition.period_required#</cfoutput></strong></li></cfif>
							<cfif rs_condition.period_optional gt 0><li>选修课 <strong><cfoutput>#rs_condition.period_optional#</cfoutput></strong></li></cfif>
						</ol>
					</div>
					</cfif>
					
				</div>

				<cfif rs_fromEditions.recordCount >
				<div id="Copy" class="tabContent">
										
					<div class="systemNotice">
						<h3><span class="img icon16x16 info"></span>复制培养方案</h3>
						<p>注意: 复制培养方案会覆盖当前已录入课程的开设学期, 课程性质相关信息. </p>
						<p>建议您仅仅在创建新年级培养方案时使用这个功能.</p>
					</div>
					
					<form id="formCopy" onSubmit="javascript:return processVerfiyForm('formCopy');" class="formWrapper" method="post" action="<cfoutput>#buildURL('programSchemaWizardCopyDo')#</cfoutput>">
						
						<input type="hidden" name="SubjectID" value="<cfoutput>#rs_subject.sbj_id#</cfoutput>" />
						<input type="hidden" name="targetEdition" value="<cfoutput>#event.getArg('Edition')#</cfoutput>" />
						
						<div class="label">
							<b>专业</b>
							<input name="targetSubjectName" id="targetSubjectName" type="text" class="typeTextReadOnly" verification="required" maxlength="30" value="<cfoutput>#rs_subject.sbj_name#</cfoutput>" />
						</div>
						
						<div class="label">
							<b>目标版本</b>
							<input name="targetSchemaEdition" id="targetSchemaEdition" type="text" class="typeTextReadOnly" verification="required" maxlength="30" value="<cfoutput>#event.getArg('Edition')#</cfoutput>版" />
						</div>
						
						<hr/>
						
						<div class="label">
							<b>来源版本</b>
							<select name="Edition">
                                <cfloop query="rs_fromEditions">
								<option value="<cfoutput>#rs_fromEditions.grade#</cfoutput>"><cfoutput>#rs_fromEditions.grade#</cfoutput>版</option>
								</cfloop>
							</select>
						</div>
						
						<div class="label">
							<b>培养方案内容</b>
							<div class="secondRow">
								<input name="selectTerm" id="selectTermAny" type="checkbox" class="typeCheckbox" value="any" checked="checked" />全部学期
								<input name="selectCourse" id="selectCourseAny" type="checkbox" class="typeCheckbox" value="any" checked="checked" />全部课程
							</div>
						</div>
						
						<div class="label hidden_elem" id="termOptions">
							<b>选择要复制的学期</b>
							<table width="300">
								<cfloop from="1" to="#rs_subject.schooling_length#" index="termYear">
									<cfset term01 = numberFormat((2 * termYear - 1), '0_') />
									<cfset term02 = numberFormat((2 * termYear), '0_') />
									<cfset termS = 'S' & termYear />
									<tr>
										<td><input verification="group" name="Term" type="checkbox" class="typeCheckbox" value="<cfoutput>#term01#</cfoutput>" checked="checked"/><cfoutput>#mathAdvice.convertTermIdxToChinese(term01)#</cfoutput></td>
										<td><input name="Term" type="checkbox" class="typeCheckbox" value="<cfoutput>#term02#</cfoutput>" checked="checked"/><cfoutput>#mathAdvice.convertTermIdxToChinese(term02)#</cfoutput></td>
										<td><cfif termYear lt 4><input name="Term" type="checkbox" class="typeCheckbox" value="<cfoutput>#termS#</cfoutput>" checked="checked"/><cfoutput>#mathAdvice.convertTermIdxToChinese(termS)#</cfoutput></cfif></td>
									</tr>
								</cfloop>
							</table>
						</div>
						
						<div class="label hidden_elem" id="courseOptions">
							<b>选择要复制的课程大类</b>
							<input name="CourseProperty" type="checkbox" class="typeCheckbox" value="1" checked="checked" verification="group"/>必修
							<input name="CourseProperty" type="checkbox" class="typeCheckbox" value="2" checked="checked"/>限选
						</div>
						
						<hr/>
						
						<div class="lable">
							<input class="button1" type="submit" value="复制培养方案" />
							<input class="button" type="reset" value="重设表格" />
						</div>
										
					</form>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							
							$("#selectCourseAny").click(function(){
								
								var $courseTrigger = $(this);
								
								if ($courseTrigger.prop("checked")) {
									$(":checkbox[name='CourseProperty']").attr("checked", "checked");
								}
								else {
									$("#courseOptions").removeClass("hidden_elem");
								}
																
							});
							
							$("#selectTermAny").click(function(){
								
								var $termTrigger = $(this);
								
								if ($termTrigger.prop("checked")) {
									$(":checkbox[name='Term']").attr("checked", "checked");
								}
								else {
									$("#termOptions").removeClass("hidden_elem");
								}
																
							});
							
						});
						// -->
						//]]>
					</script>
					
				</div>
				</cfif>
			</div>
		</li>
	</ul>
</div>